package com.casic.modules.ddpin.controller;

import com.casic.common.base.entity.PageEntity;
import com.casic.common.utils.R;
import com.casic.common.validator.group.AddGroup;
import com.casic.common.validator.group.UpdateGroup;
import com.casic.modules.ddpin.entity.QyxxDdDdywNewEntity;
import com.casic.modules.ddpin.service.QyxxDdDdywNewService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 典当品信息
 * 
 * @author ws
 * @email 123456789@qq.com
 * @date 2019-05-13 13:44:14
 */
@RestController
@RequestMapping("qyxxddddywnew")
public class QyxxDdDdywNewController {
	@Autowired
	private QyxxDdDdywNewService qyxxDdDdywNewService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("qyxxddddywnew:list")
	public R list(@RequestParam Map<String, Object> params){
        PageEntity<QyxxDdDdywNewEntity> page=qyxxDdDdywNewService.findPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("qyxxddddywnew:info")
	public R info(@PathVariable("id") String id){
		QyxxDdDdywNewEntity qyxxDdDdywNew = qyxxDdDdywNewService.findById(id);
		return R.ok().put("qyxxDdDdywNew", qyxxDdDdywNew);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("qyxxddddywnew:save")
	public R save(@RequestBody @Validated(AddGroup.class) QyxxDdDdywNewEntity qyxxDdDdywNew, Errors errors){
		if(errors.hasErrors()) {
			return R.error(400, errors.getAllErrors().get(0).getDefaultMessage());
		}
		qyxxDdDdywNewService.save(qyxxDdDdywNew);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("qyxxddddywnew:update")
	public R update(@RequestBody @Validated(UpdateGroup.class) QyxxDdDdywNewEntity qyxxDdDdywNew, Errors errors){
		if(errors.hasErrors()) {
			return R.error(400, errors.getAllErrors().get(0).getDefaultMessage());
		}
		qyxxDdDdywNewService.edit(qyxxDdDdywNew);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("qyxxddddywnew:delete")
	public R delete(@RequestBody String[] ids){
		qyxxDdDdywNewService.removeByIds(ids);
		return R.ok();
	}
	
}
